package service

import (
	"context"
	"gitee.com/jinmingzhi/cdce-service/internal/model"
	"gitee.com/jinmingzhi/cdce-service/internal/repository"
)

type SchoolReport interface {
	FindScoreByUid(ctx context.Context, uid uint32) ([]*model.Score, error)
	Add(ctx context.Context, schoolReports []*model.SchoolReport, pays []*model.Pay) error
}

type schoolReportImpl struct {
	SchoolReportRepo repository.SchoolReport
	PayRepo          repository.Pay
}

func NewSchoolReport(school_report_repo repository.SchoolReport, pay_repo repository.Pay) SchoolReport {
	return &schoolReportImpl{
		SchoolReportRepo: school_report_repo,
		PayRepo:          pay_repo,
	}
}

func (s *schoolReportImpl) FindScoreByUid(ctx context.Context, uid uint32) ([]*model.Score, error) {
	return s.SchoolReportRepo.FindScoreAllByUid(ctx, uid)
}

func (s *schoolReportImpl) Add(ctx context.Context, schoolReports []*model.SchoolReport, pays []*model.Pay) error {
	for _, v := range schoolReports {
		err := s.SchoolReportRepo.AddOne(ctx, v)
		if err != nil {
			return err
		}
	}
	for _, v := range pays {
		err := s.PayRepo.AddOne(ctx, v)
		if err != nil {
			return err
		}
	}
	return nil
}
